#!/usr/bin/env python
# -*- coding: utf-8 -*-
# title       :
# author      : jarry

import sys
import os
import logging
from SceneCheckTool.checkScript.CheckBase import CheckBase

try:
    import maya.cmds as cmds
    # import pymel.core as pm
    import JTK.jmaya.core as jmc

except:
    pass

logging.basicConfig()
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)


class NameErrorShaders(CheckBase):
    def __init__(self):
        super(NameErrorShaders, self).__init__()
        pass

    def check(self):
        self.error_node = []
        # r = self.init_file()
        # if r != True:
        #     return r
        result_proc = jmc.list_all_shader_node()
        # print(self.asset_root_set_name)
        for s in result_proc:
            if s.startswith('pasted__'):
                self.error_node.append(s)
            # elif not s.startswith(self.asset_root_set_name):
            #     self.error_node.append(s)

        if self.error_node:
            result_log = u'Error:%s\n' % self.error_node
        else:
            result_log = u'Succeed:没有问题\n'

        return result_log

    def fix(self):
        self.check()
        if self.error_node:
            try:
                for i in self.error_node:
                    if cmds.lockNode(i, q=1, l=1) == [True]:
                        cmds.lockNode(i, l=0)
                    cmds.delete(i)
                result_log = u'Succeed:%s已经删除\n' % self.error_node
                return result_log
            except:
                return u'Error:%s没有删除成功\n' % self.error_node
